
#ifndef   __SIMPHONY_PREFIXS
#define   __SIMPHONY_PREFIXS

#include "eeprom.h"

#define   PREFIX_NOT_EXISTS 	(-1)
#define   PREFIX_EXISTS			(-2)
#define   NAME_WAS_NOT_FOUND	(-3)
#define   NO_FREE_ENTRY			(-4)
#define   FREE_ENTRY				0xFFFFFFFF
#define   EMPTY					0xFF



#define   DEFAULT_CALL_PREFIX		0xFF999999
#define   DEFAULT_SMS_PREFIX		0xFF888888

typedef union
{
		unsigned char Data[PREFIX_SIZE];
		struct 
		{
				unsigned char UnitLong;			/* in sec */
				unsigned char ConnectionCost;	/* how many unit to pay if connection was established  */
				unsigned long UnitCost;			/* Example: 2.50 must be write 250 or 19000.00 -> 1900000 (without the point)*/
				unsigned long PrefixName; 		/* BCD format. Example: 054 -> 0xFFFFF054 or 052614 -> 0xFF052614 */
		}Field;

}PREFIX;

typedef struct 
{
		unsigned int Index;
		PREFIX Prefix;
}VIEW_PREFIX;

//extern PREFIX Prefix;


void PrefixClearAll ( void ); 

/* Input: Prefix Name, point to PREFIX type data object.
	Output: FALSE if Prefix not found, in other case return Index of object and fill the object of PREFIX data type  */
int PrefixFind( unsigned long PrefixName, PREFIX* );

/* Input: Index of object, point to PREFIX type data object; 
   Output: returns Index of prefix and fill the object of PREFIX data type, in other case returns "-1" if the Prefix already exist */
int PrefixWrite( unsigned int Index, PREFIX* );

/* Input: Index of object; point to PREFIX type data object.
   Output: Fill the object of PREFIX data type*/
void PrefixLoad_Index( unsigned int Index, PREFIX* );

/* if the Name is not exist, then return NAME_WAS_NOT_FOUND; if the Name exist - return Index of the Prefix Entry */
int PrefixLoad_Name( unsigned long Name, PREFIX* Prefix );


int PrefixFindFreeEntry ( void );
void PrefixDelete( unsigned long PrefixName );
unsigned long PrefixGetName( unsigned int Index );

/* Return PrefixName*/
unsigned long Find_Up( unsigned char  );
unsigned long Find_Down( unsigned char  );
/*  */
int PrefixGetIndex( unsigned long Name );

int PrefixRecord( PREFIX* Prefix );

#endif


